package com.bilibili.juc.interrupt;

import java.util.concurrent.TimeUnit;

public class InterruptTestDemo {

    //static volatile boolean isStop = false;
    static  boolean isStop = false ;


    public static void main(String[] args) {
        new Thread(
                ()->{
                    while(true){
                        if(isStop){
                            System.out.println(Thread.currentThread().getName()+"\t isStop 修改为ture,程序停止");
                            break;
                        }
                        System.out.println("---- hello volatile t1");
                    }

                },"t1"
        ).start();

        try{
            TimeUnit.MILLISECONDS.sleep(10);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        new Thread(
                ()->{
                    System.out.println(Thread.currentThread().getName()+"-------");
                    isStop = true ;
                    System.out.println(Thread.currentThread().getName()+"after-------");
                },"t2"
        ).start();

        System.out.println(Thread.currentThread().getName()+"-------");
    }
}
